#include <xp/bas/stdlib.h>
#include <xp/bas/stdio.h>

int xp_main ()
{
	xp_byte_t buf[8];
	xp_byte_t buf2[6];
	xp_size_t n, xn, i;

	//n = xp_encode_base64 ("", 0, buf, xp_sizeof(buf), &xn);
	//n = xp_encode_base64 ("\x12", 1, buf, xp_sizeof(buf), &xn);
	//n = xp_encode_base64 ("\x12\x20", 2, buf, xp_sizeof(buf), &xn);
	//n = xp_encode_base64 ("\x12\x20\x99", 3, buf, xp_sizeof(buf), &xn);
	//n = xp_encode_base64 ("\x12\x20\x99\x89", 4, buf, xp_sizeof(buf), &xn);
	n = xp_encode_base64 ("\x12\x20\x99\x89\xFF", 5, buf, xp_sizeof(buf), &xn);
	if (xn != n) {
		xp_printf (XP_TEXT("warning: buffer too small - %lu/%lu\n"), 
			(unsigned long)n, (unsigned long)xn);
	}

	for (i = 0; i < n; i++) {
		xp_printf (XP_TEXT("%c"), buf[i]);
	}
	xp_printf (XP_TEXT("\n"));

	n = xp_decode_base64 (buf, n, buf2, xp_sizeof(buf2), &xn);
	if (xn != n) {
		xp_printf (XP_TEXT("warning: buffer too small - %lu/%lu\n"), 
			(unsigned long)n, (unsigned long)xn);
	}

	for (i = 0; i < n; i++) {
		xp_printf (XP_TEXT("\\x%x"), buf2[i]);
	}

	xp_printf (XP_TEXT("\n"));

	return 0;
}

